<?php

namespace App\Http\Controllers\Dashboard;

use App\Http\Controllers\Controller;
use App\Http\Requests\Dashboard\UserWorkReviewRequest;
use App\Http\Resources\Dashboard\UserWorkResource;
use App\Models\User;
use App\Models\UserWork;
use Illuminate\Http\Request;

class UserWorkController extends Controller
{
    public function index(Request $request)
    {

        $userWork = UserWork::with(['user', 'work']);
//        if ($request->has('title')) {
//            $skill = $userWork->like('title', $request->title);
//        }
//        if ($request->has('description')) {
//            $skill = $skill->like('description', $request->description);
//        }
//        if ($request->has('trashed')) {
//            $skill = $skill->trashedType($request->trashed);
//        }
//        $skill = $skill->withCount(['careers', 'courses']);
        return UserWorkResource::collection($userWork->paginate($request->get('per_page', 15)));
    }

    public function update(UserWorkReviewRequest $request)
    {
        UserWork::where('user_id', $request->user_id)->where('work_id', $request->work_id)->update(['review' => ['mark' => $request->mark]]);
    }
}
